package com.kstech.exccheck.receiver;

import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;

import com.kstech.exccheck.R;
import com.kstech.exccheck.util.AppContext;

/**
 * @author wanghaibin
 * @created 2016-10-20 ����9:10:27
 * @since v1.0
 * replacede by NetWorkStatusListener{@link com.kstech.exccheck.listener.NetWorkStatusListener}
 */
public class ConnStatusReceiver extends BroadcastReceiver {

	private static Map<String, ImageView> connStatusViewMap = new HashMap<String, ImageView>();

	public ImageView initConnStatusImageView(Activity context) {
		ImageView connectionStatusImgView = (ImageView) context.findViewById(R.id.connStatusId);
		connStatusViewMap.put(this.getClass().getName(),
				connectionStatusImgView);
		return connectionStatusImgView;
	}

	/**
	 * 通知UI线程改变链接状态图标
	 */
	@Override
	public void onReceive(Context arg0, Intent intent) {
		for (ImageView view : connStatusViewMap.values()) {
			int resourceId = R.drawable.link;
			//interrupted true ：表示断开链接   false：表示链接正常
			if (intent.getBooleanExtra("interrupted", true)) {
				resourceId = R.drawable.link_no;
			}
			view.setBackground(AppContext.context.getDrawable(resourceId));
		}

	}

}
